package com.yf.construction.dss.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yf.base.api.api.dto.PagingReqDTO;
import com.yf.construction.dss.convert.DssConvert;
import com.yf.construction.dss.dto.ConstructionDssDTO;
import com.yf.construction.dss.entity.ConstructionDss;
import com.yf.construction.dss.mapper.ConstructionDssMapper;
import com.yf.construction.dss.service.ConstructionDssService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

;

/**
 * <p>
 * 业务实现类
 * </p>
 *
 * @author anyone
 * @since 2024-09-13 16:38
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class ConstructionDssServiceImpl extends ServiceImpl<ConstructionDssMapper, ConstructionDss> implements ConstructionDssService {

    @Override
    public Page<ConstructionDssDTO> paging(PagingReqDTO<ConstructionDssDTO> reqDTO) {
        //查询条件
        QueryWrapper<ConstructionDss> wrapper = new QueryWrapper<>();
        // 请求参数
        ConstructionDssDTO params = reqDTO.getParams();
        wrapper.eq(StrUtil.isNotBlank(params.getDecisionCriteria()), "decision_criteria", params.getDecisionCriteria());
        wrapper.eq(StrUtil.isNotBlank(params.getVisualizationType()), "visualization_type", params.getVisualizationType());
        //获得数据
        Page<ConstructionDss> page = this.page(reqDTO.toPage(), wrapper);
        //转换结果
        Page<ConstructionDssDTO> pageData = DssConvert.INSTANCE.pageEntityDto(page);
        return pageData;
    }


    @Override
    public void save(ConstructionDssDTO reqDTO) {
        //复制参数
        ConstructionDss entity = DssConvert.INSTANCE.dtoToEntity(reqDTO);
        this.saveOrUpdate(entity);
    }

    @Override
    public void delete(List<String> ids) {
        //批量删除
        this.removeByIds(ids);
    }

    @Override
    public ConstructionDssDTO detail(String id) {
        ConstructionDss entity = this.getById(id);
        return DssConvert.INSTANCE.entityToDto(entity);
    }

    @Override
    public List<ConstructionDssDTO> list(ConstructionDssDTO reqDTO) {
        //分页查询并转换
        QueryWrapper<ConstructionDss> wrapper = new QueryWrapper<>();
        //转换并返回
        List<ConstructionDss> list = this.list(wrapper);
        //转换数据
        return DssConvert.INSTANCE.listEntityDto(list);
    }
}
